package com.as.manager;

import java.util.List;

import com.as.dao.RankDao;
import com.as.entity.Rank;
import com.as.tools.ArcTools;

public class RankManagerImpl implements RankManager{
	private ArcTools arcTools;
	private RankDao rankDao;
	public void setArcTools(ArcTools arcTools) {
		this.arcTools = arcTools;
	}
	public void setRankDao(RankDao rankDao) {
		this.rankDao = rankDao;
	}
	@Override
	public Rank getRank(String rankId) {
		return rankDao.getById(rankId);
	}
	@Override
	public boolean addRank(Rank rank) {
		try{
			rankDao.save(rank);
			return true;
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
	}
	@Override
	public boolean updateRank(Rank rank) {
		try{
			rankDao.update(rank);
			return true;
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
	}
	@Override
	public boolean deleteRank(String rankId) {
		try{
			rankDao.delete(rankId);
			return true;
		}catch(Exception e){
			e.printStackTrace();
			return false;
		}
	}
	@Override
	public List<Rank> getAllRanks() {
		return rankDao.findAll();
	}
	@Override
	public int getOneRank(int times) {
		return rankDao.getOneRank(times);
	}
	@Override
	public Rank getRankByUserid(String userid) {
		return rankDao.getRankByUserid(userid);
	}
	@Override
	public Rank createRank(String userid, int rightTimes) {
		String rankid = arcTools.createId();
		return  new Rank(rankid, userid, 0, rightTimes);
	}
	@Override
	public List<Object> getTopThree() {
		return rankDao.getTopThree();
	}
}
